package com.ruoyi.asset.controller;

import java.util.List;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.asset.domain.AstDeviceRecord;
import com.ruoyi.asset.service.IAstDeviceRecordService;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 设备操作记录Controller
 * 
 * @author xunzhe
 * @date 2024-06-12
 */
@Controller
@RequestMapping("/asset/deviceRecord")
public class AstDeviceRecordController extends BaseController
{
    private String prefix = "asset/deviceRecord";

    @Autowired
    private IAstDeviceRecordService astDeviceRecordService;

    @RequiresPermissions("asset:deviceRecord:view")
    @GetMapping(value = { "", "/{deviceId}"})
    public String deviceRecord(@PathVariable(value = "deviceId", required = false) Long deviceId, ModelMap mmap)
    {
        mmap.put("deviceId",deviceId);
        return prefix + "/deviceRecord";
    }

    /**
     * 查询设备操作记录列表
     */
    @RequiresPermissions("asset:deviceRecord:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(AstDeviceRecord astDeviceRecord)
    {
        startPage();
        List<AstDeviceRecord> list = astDeviceRecordService.selectAstDeviceRecordList(astDeviceRecord);
        return getDataTable(list);
    }

    /**
     * 导出设备操作记录列表
     */
    @RequiresPermissions("asset:deviceRecord:export")
    @Log(title = "设备操作记录", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(AstDeviceRecord astDeviceRecord)
    {
        List<AstDeviceRecord> list = astDeviceRecordService.selectAstDeviceRecordList(astDeviceRecord);
        ExcelUtil<AstDeviceRecord> util = new ExcelUtil<AstDeviceRecord>(AstDeviceRecord.class);
        return util.exportExcel(list, "设备操作记录数据");
    }

    /**
     * 新增设备操作记录
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存设备操作记录
     */
    @RequiresPermissions("asset:deviceRecord:add")
    @Log(title = "设备操作记录", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(AstDeviceRecord astDeviceRecord)
    {
        return toAjax(astDeviceRecordService.insertAstDeviceRecord(astDeviceRecord));
    }

    /**
     * 修改设备操作记录
     */
    @RequiresPermissions("asset:deviceRecord:edit")
    @GetMapping("/edit/{recordId}")
    public String edit(@PathVariable("recordId") Long recordId, ModelMap mmap)
    {
        AstDeviceRecord astDeviceRecord = astDeviceRecordService.selectAstDeviceRecordByRecordId(recordId);
        mmap.put("astDeviceRecord", astDeviceRecord);
        return prefix + "/edit";
    }

    /**
     * 修改保存设备操作记录
     */
    @RequiresPermissions("asset:deviceRecord:edit")
    @Log(title = "设备操作记录", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(AstDeviceRecord astDeviceRecord)
    {
        return toAjax(astDeviceRecordService.updateAstDeviceRecord(astDeviceRecord));
    }

    /**
     * 删除设备操作记录
     */
    @RequiresPermissions("asset:deviceRecord:remove")
    @Log(title = "设备操作记录", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(astDeviceRecordService.deleteAstDeviceRecordByRecordIds(ids));
    }
}
